package com.xy.pattern.cor;

import java.util.ArrayList;
import java.util.List;

public class ChainFilter implements Filter {
    private List<Filter> filterList = new ArrayList<>();
    private int index = 0;

    public ChainFilter add(Filter filter) {
        filterList.add(filter);
        return this;
    }

    @Override
    public void doFilter(String input, String output, ChainFilter chainFilter) {
        if (index == filterList.size()) {
            return;
        }
        Filter filter = filterList.get(index);
        index++;
        filter.doFilter(input, output, chainFilter);
    }
}
